home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / po.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  15KB  |  594 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities Port Setup                    ** */
  4. /* **            Copright (C) 1992-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include "janus.h"
  10. #include "ATUtilities.h"
  11.  
  12. UBYTE *PortSetupPort="ATUtilities Port Setup";
  13. UBYTE *PrefsName="AT:Prefs/PortSetup.prefs";
  14. UBYTE *DefPrefsName="AT:Prefs/PortSetupDefault.prefs";
  15. UBYTE *HelpName="AT:Help/PortSetup.help";
  16.  
  17. struct PortPrefs
  18. {
  19.  UWORD LPT[4];
  20.  UWORD LPTTimeOut[4];
  21.  UWORD COM[4];
  22.  UWORD COMTimeOut[4];
  23. };
  24.  
  25. struct PortPrefs PortPrefs;
  26. struct PortPrefs DefPortPrefs=
  27. {
  28.  0,0,0,0,
  29.  20,20,20,20,
  30.  0,0,0,0,
  31.  20,20,20,20
  32. };
  33.  
  34. struct JanusBase *JanusBase;
  35. struct Library   *GfxBase;
  36. struct Library   *IntuitionBase;
  37. struct Library   *ATUtilitiesBase;
  38.  
  39. struct DualPortedMemory *dpm;
  40. struct ExtSetupSig  *ExtSetupSig;
  41. struct Window       *WindowPtr;
  42. struct RastPort     *rp;
  43. struct CommMemory   *jhbyte,*jhword;
  44. struct JRemember    *JRemember=NULL;
  45.  
  46. LONG  JanusSignal;
  47. LONG  PortSignal;
  48. ULONG JanusSignalMask;
  49. ULONG PortSignalMask;
  50. ULONG WaitSignalMask;
  51. ULONG Signale;
  52.  
  53. BOOL defOkay=FALSE;
  54.  
  55. VOID  HandleInt();
  56. VOID  ShowInfo();
  57. VOID  OpenAll();
  58. VOID  CloseAll();
  59. BOOL  EinstellungenAendern();
  60. UWORD TimeOut();
  61. UWORD Wahl();
  62.  
  63. struct MsgPort  *Port;
  64.  
  65.  
  66. /* Installationsroutine */
  67. VOID main()
  68. {
  69.  REGISTER UWORD        i;
  70.  REGISTER BOOL         bool;
  71.  register struct Task *task;
  72.  
  73.  OpenAll();
  74.  bool=FALSE;
  75.  task=FindTask(NULL);
  76.  while(bool==FALSE)
  77.   {
  78.    Signale=Wait(WaitSignalMask);
  79.    if(Signale & PortSignalMask)
  80.     {
  81.      i=Received(Port);
  82.      switch(i)
  83.       {
  84.        case UTILITY_CALL:
  85.          bool=EinstellungenAendern();
  86.         break;
  87.        case UTILITY_QUIT:
  88.          DisplayBeep(NULL);
  89.          bool=TRUE;
  90.         break;
  91.        case UTILITY_INFO:
  92.          ShowInfo();
  93.         break;
  94.        case UTILITY_HELP:
  95.          Help(HelpName,0);
  96.         break;
  97.       }
  98.     }
  99.    if(Signale & JanusSignalMask)
  100.     {
  101.      HandleInt();
  102.     }
  103.   }
  104.  CloseAll();
  105. }
  106.  
  107. /* PC-Befehle ausführen */
  108. VOID HandleInt()
  109. {
  110.  register struct FileHandle *fh;
  111.  
  112.  switch(jhword->Arg1)
  113.   {
  114.    case 1:
  115.      DefPortPrefs.LPT[0]=jhword->Arg2;
  116.      DefPortPrefs.LPT[1]=jhword->Arg3;
  117.      DefPortPrefs.LPT[2]=jhword->Arg4;
  118.      DefPortPrefs.LPT[3]=jhword->Arg5;
  119.      jhword->Arg2=PortPrefs.LPT[0];
  120.      jhword->Arg3=PortPrefs.LPT[1];
  121.      jhword->Arg4=PortPrefs.LPT[2];
  122.      jhword->Arg5=PortPrefs.LPT[3];
  123.     break;
  124.    case 2:
  125.      DefPortPrefs.LPTTimeOut[0]=jhword->Arg2;
  126.      DefPortPrefs.LPTTimeOut[1]=jhword->Arg3;
  127.      DefPortPrefs.LPTTimeOut[2]=jhword->Arg4;
  128.      DefPortPrefs.LPTTimeOut[3]=jhword->Arg5;
  129.      jhword->Arg2=PortPrefs.LPTTimeOut[0];
  130.      jhword->Arg3=PortPrefs.LPTTimeOut[1];
  131.      jhword->Arg4=PortPrefs.LPTTimeOut[2];
  132.      jhword->Arg5=PortPrefs.LPTTimeOut[3];
  133.     break;
  134.    case 3:
  135.      DefPortPrefs.COM[0]=jhword->Arg2;
  136.      DefPortPrefs.COM[1]=jhword->Arg3;
  137.      DefPortPrefs.COM[2]=jhword->Arg4;
  138.      DefPortPrefs.COM[3]=jhword->Arg5;
  139.      jhword->Arg2=PortPrefs.COM[0];
  140.      jhword->Arg3=PortPrefs.COM[1];
  141.      jhword->Arg4=PortPrefs.COM[2];
  142.      jhword->Arg5=PortPrefs.COM[3];
  143.     break;
  144.    case 4:
  145.      DefPortPrefs.COMTimeOut[0]=jhword->Arg2;
  146.      DefPortPrefs.COMTimeOut[1]=jhword->Arg3;
  147.      DefPortPrefs.COMTimeOut[2]=jhword->Arg4;
  148.      DefPortPrefs.COMTimeOut[3]=jhword->Arg5;
  149.      jhword->Arg2=PortPrefs.COMTimeOut[0];
  150.      jhword->Arg3=PortPrefs.COMTimeOut[1];
  151.      jhword->Arg4=PortPrefs.COMTimeOut[2];
  152.      jhword->Arg5=PortPrefs.COMTimeOut[3];
  153.     break;
  154.    case 10:
  155.      if(defOkay==FALSE)
  156.       {
  157.        fh=Open(DefPrefsName,MODE_NEWFILE);
  158.        if(fh!=NULL)
  159.         {
  160.          Write(fh,&DefPortPrefs,sizeof(struct PortPrefs));
  161.          Close(fh);
  162.         }
  163.        defOkay=TRUE;
  164.       }
  165.     break;
  166.   }
  167.  SendJanusInt(30);
  168. }
  169.  
  170.  
  171. /* Installationsroutine */
  172. VOID OpenAll()
  173. {
  174.  REGISTER UWORD              i;
  175.  register struct MsgPort    *p;
  176.  register struct FileHandle *fh;
  177.  
  178.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  179.  if(ATUtilitiesBase==NULL)
  180.   {
  181.    printf("ERROR: Kann ATUtilities-Library nicht öffnen.\n");
  182.    CloseAll();
  183.   }
  184.  
  185.  GfxBase=OpenLibrary("graphics.library",0L);
  186.  IntuitionBase=OpenLibrary("intuition.library",0L);
  187.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  188.   {
  189.    CloseAll();
  190.   }
  191.  
  192.  p=FindPort(PortSetupPort);
  193.  if(p!=NULL)
  194.   {
  195.    InfoRequest("ATUtilities Port Setup-Handler ist schon aktiv.");
  196.    CloseAll();
  197.   }
  198.  
  199.  JanusBase=OpenLibrary("janus.library",0L);
  200.  if(JanusBase==NULL)
  201.   {
  202.    ErrorRequest(ERROR_JANUS);
  203.    CloseAll();
  204.   }
  205.  dpm=MakeWordPtr(JanusBase->ParameterRAM);
  206.  
  207.  Port=CreatePort(PortSetupPort,0L);
  208.  if(Port==NULL)
  209.   {
  210.    ErrorRequest(ERROR_MPORT);
  211.    CloseAll();
  212.   }
  213.  
  214.  fh=Open(DefPrefsName,MODE_OLDFILE);
  215.  if(fh!=NULL)
  216.   {
  217.    Read(fh,&DefPortPrefs,sizeof(struct PortPrefs));
  218.    Close(fh);
  219.   }
  220.  
  221.  fh=Open(PrefsName,MODE_OLDFILE);
  222.  if(fh!=NULL)
  223.   {
  224.    Read(fh,&PortPrefs,sizeof(struct PortPrefs));
  225.    Close(fh);
  226.   }
  227.  else
  228.   {
  229.    CopyMem(&DefPortPrefs,&PortPrefs,sizeof(struct PortPrefs));
  230.   }
  231.  
  232.  ExtSetupSig=CreatePublicHandler(30);
  233.  if(ExtSetupSig==NULL)
  234.   {
  235.    CloseAll();
  236.   }
  237.  
  238.  jhword=ExtSetupSig->WordAccess;
  239.  jhbyte=ExtSetupSig->ByteAccess;
  240.  PortSignal=Port->mp_SigBit;
  241.  PortSignalMask=(1L<<PortSignal);
  242.  JanusSignal=ExtSetupSig->JanusSignal;
  243.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  244.  WaitSignalMask=PortSignalMask+JanusSignalMask;
  245.  ChangeTaskPri(5);
  246. }
  247.  
  248.  
  249. /* Programmende */
  250. VOID CloseAll()
  251. {
  252.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  253.  if(Port) DeletePort(Port);
  254.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  255.  if(GfxBase) CloseLibrary(GfxBase);
  256.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  257.  if(JanusBase) CloseLibrary(JanusBase);
  258.  exit(0);
  259. }
  260.  
  261.  
  262. /* Einstellungsfenster */
  263. BOOL EinstellungenAendern()
  264. {
  265.  UBYTE                         tex[60];
  266.  REGISTER UWORD                i,j,id;
  267.  REGISTER BOOL                 bool,ende;
  268.  REGISTER ULONG                Class;
  269.  register struct Window       *win;
  270.  register struct Gadget       *gad;
  271.  register struct IntuiMessage *msg;
  272.  register struct FileHandle   *fh;
  273.  register struct RastPort     *rp;
  274.  register struct TextFont     *opal;
  275.  
  276.  bool=FALSE;
  277.  win=CreateStdWindow("ATUtilities - Port Setup Einstellungen",
  278.                      75,75,450,95,GADGETUP|CLOSEWINDOW,
  279.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  280.  if(win!=NULL)
  281.   {
  282.    rp=win->RPort;
  283.    opal=GetOpalFont();
  284.    SetFont(rp,opal);
  285.    CreateBoolGadget(win,10,15,155,12,"Einstellungen okay",1);
  286.    CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
  287.    CreateBoolGadget(win,335,15,50,12,"Info",3);
  288.    CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
  289.    for(i=0;i<=3;i++)
  290.     {
  291.      if(PortPrefs.LPT[i]!=0)
  292.        sprintf(&tex,"LPT%ld: $%03lx",i+1,PortPrefs.LPT[i]);
  293.      else
  294.        sprintf(&tex,"LPT%ld: None",i+1);
  295.      CreateBoolGadget(win,10,35+(i*14),100,12,&tex,10+i);
  296.      sprintf(&tex,"T-Out: %ld",PortPrefs.LPTTimeOut[i]);
  297.      CreateBoolGadget(win,115,35+(i*14),100,12,&tex,20+i);
  298.      if(PortPrefs.COM[i]!=0)
  299.        sprintf(&tex,"COM%ld: $%03lx",i+1,PortPrefs.COM[i]);
  300.      else
  301.        sprintf(&tex,"COM%ld: None",i+1);
  302.      CreateBoolGadget(win,235,35+(i*14),100,12,&tex,30+i);
  303.      sprintf(&tex,"T-Out: %ld",PortPrefs.COMTimeOut[i]);
  304.      CreateBoolGadget(win,340,35+(i*14),100,12,&tex,40+i);
  305.     }
  306.  
  307.    ende=FALSE;
  308.    while(ende==FALSE)
  309.     {
  310.      WaitPort(win->UserPort);
  311.      msg=GetMsg(win->UserPort);
  312.      gad=msg->IAddress;
  313.      Class=msg->Class;
  314.      ReplyMsg(msg);
  315.      switch(Class)
  316.       {
  317.        case CLOSEWINDOW:
  318.          ende=TRUE;
  319.         break;
  320.        case GADGETUP:
  321.          id=gad->GadgetID;
  322.          switch(id)
  323.           {
  324.            case 1:
  325.              fh=Open(PrefsName,MODE_NEWFILE);
  326.              if(fh!=NULL)
  327.               {
  328.                Write(fh,&PortPrefs,sizeof(struct PortPrefs));
  329.                Close(fh);
  330.               }
  331.              ende=TRUE;
  332.             break;
  333.            case 2:
  334.              ende=TRUE; bool=TRUE;
  335.             break;
  336.            case 3:
  337.              ShowInfo();
  338.             break;
  339.            case 4:
  340.              Help(HelpName,0);
  341.             break;
  342.            default:
  343.             if(id<20)
  344.              {
  345.               j=id-10;
  346.               sprintf(&tex,"Adresse von LPT%ld festlegen",j+1);
  347.               PortPrefs.LPT[j]=Wahl(&tex,PortPrefs.LPT[j],DefPortPrefs.LPT[j]);
  348.               if(PortPrefs.LPT[j]!=0)
  349.                 sprintf(&tex,"LPT%ld: $%03lx",j+1,PortPrefs.LPT[j]);
  350.               else
  351.                 sprintf(&tex,"LPT%ld: None",j+1);
  352.               DrawCPTextBorder(win,10,35+(j*14),100,12,&tex);
  353.              }
  354.             else if(id<30)
  355.              {
  356.               j=id-20;
  357.               sprintf(&tex,"Time-Out von LPT%ld festlegen",j+1);
  358.               PortPrefs.LPTTimeOut[j]=TimeOut(&tex,PortPrefs.LPTTimeOut[j],
  359.                                                    DefPortPrefs.LPTTimeOut[j]);
  360.               sprintf(&tex,"T-Out: %ld",PortPrefs.LPTTimeOut[j]);
  361.               DrawCPTextBorder(win,115,35+(j*14),100,12,&tex);
  362.              }
  363.             else if(id<40)
  364.              {
  365.               j=id-30;
  366.               sprintf(&tex,"Adresse von COM%ld festlegen",j+1);
  367.               PortPrefs.COM[j]=Wahl(&tex,PortPrefs.COM[j],DefPortPrefs.COM[j]);
  368.               if(PortPrefs.COM[j]!=0)
  369.                 sprintf(&tex,"COM%ld: $%03lx",j+1,PortPrefs.COM[j]);
  370.               else
  371.                 sprintf(&tex,"COM%ld: None",j+1);
  372.               DrawCPTextBorder(win,235,35+(j*14),100,12,&tex);
  373.              }
  374.             else if(id<50)
  375.              {
  376.               j=id-40;
  377.               sprintf(&tex,"Time-Out von COM%ld festlegen",j+1);
  378.               PortPrefs.COMTimeOut[j]=TimeOut(&tex,PortPrefs.COMTimeOut[j],
  379.                                                    DefPortPrefs.COMTimeOut[j]);
  380.               sprintf(&tex,"T-Out: %ld",PortPrefs.COMTimeOut[j]);
  381.               DrawCPTextBorder(win,340,35+(j*14),100,12,&tex);
  382.              }
  383.           }
  384.         break;
  385.       }
  386.     }
  387.    DeleteStdWindow(win);
  388.   }
  389.  if(bool==TRUE) DisplayBeep(NULL);
  390.  return(bool);
  391. }
  392.  
  393.  
  394. /* Information */
  395. VOID ShowInfo()
  396. {
  397.  InformationBox("ATUtilities Port Setup - Information",
  398.                 "$VER: Port Setup - Version 4.0",
  399.                 "Copyright (C) 1992-1994 by",
  400.                 "Thomas Dreibholz",
  401.                 "All rights reserved.",
  402.                 "AT:Icons/Utility");
  403. }
  404.  
  405.  
  406. /* Adresse ändern */
  407. UWORD Wahl(titel,alt,def)
  408.  UBYTE *titel;
  409.  UWORD  alt,def;
  410. {
  411.  UBYTE                         str[40];
  412.  UBYTE                         cmd[10];
  413.  UBYTE                         tex[3];
  414.  UBYTE                         phase;
  415.  UWORD                         neu;
  416.  REGISTER UWORD                i,j,k;
  417.  REGISTER BOOL                 ende;
  418.  REGISTER ULONG                Class;
  419.  register struct Window       *win;
  420.  register struct Gadget       *gad;
  421.  register struct IntuiMessage *msg;
  422.  register struct RastPort     *rp;
  423.  register struct TextFont     *opal;
  424.  
  425.  neu=alt;
  426.  win=CreateStdWindow(titel,75,75,450,95,GADGETUP|CLOSEWINDOW,
  427.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  428.  if(win!=NULL)
  429.   {
  430.    rp=win->RPort;
  431.    opal=GetOpalFont();
  432.    SetFont(rp,opal);
  433.    CreateBoolGadget(win,10,15,115,12,"Okay",100);
  434.    CreateBoolGadget(win,130,15,115,12,"Abbruch",200);
  435.    sprintf(&str,"Original: $%03lx",def);
  436.    CreateBoolGadget(win,250,15,190,12,&str,300);
  437.    k=0; phase='0';
  438.    for(i=0;i<=3;i++)
  439.     {
  440.      for(j=0;j<=3;j++)
  441.       {
  442.        sprintf(&tex,"%c",phase);
  443.        CreateBoolGadget(win,10+(j*28),35+(i*13),26,12,&tex,k);
  444.        k++; phase++;
  445.        if(phase==':') phase='A';
  446.       }
  447.     }
  448.    k=0;
  449.    sprintf(&str,"Alte Portadresse:  $%03lx",alt);
  450.    DrawNTextBorder(win,130,35,310,12,&str);
  451.    SelectStdFPen(rp);
  452.    WriteText(rp,145,58,"Bitte neue Portadresse eingeben,");
  453.    WriteText(rp,145,68,"$000 für keine Schnittstelle.");
  454.    sprintf(&str,"Neue Portadresse:  $%03lx",neu);
  455.    DrawNTextBorder(win,130,74,310,12,&str);
  456.  
  457.    phase=0;
  458.    ende=FALSE;
  459.    while(ende==FALSE)
  460.     {
  461.      WaitPort(win->UserPort);
  462.      msg=GetMsg(win->UserPort);
  463.      gad=msg->IAddress;
  464.      Class=msg->Class;
  465.      ReplyMsg(msg);
  466.      switch(Class)
  467.       {
  468.        case CLOSEWINDOW:
  469.          neu=alt;
  470.          ende=TRUE;
  471.         break;
  472.        case GADGETUP:
  473.          i=gad->GadgetID;
  474.          switch(i)
  475.           {
  476.            case 100:
  477.              if(phase!=0) neu=alt;
  478.              ende=TRUE;
  479.             break;
  480.            case 200:
  481.              neu=alt;
  482.              ende=TRUE;
  483.             break;
  484.            case 300:
  485.              neu=def;
  486.              ende=TRUE;
  487.             break;
  488.            default:
  489.              j=i;
  490.              switch(phase)
  491.               {
  492.                case 0:
  493.                  neu=j*256;
  494.                  phase++;
  495.                  sprintf(&cmd,"%01lx--",j);
  496.                 break;
  497.                case 1:
  498.                  neu=neu+(j*16);
  499.                  phase++;
  500.                  sprintf(&cmd,"%02lx-",neu/16);
  501.                 break;
  502.                default:
  503.                  neu=neu+j;
  504.                  phase=0;
  505.                  sprintf(&cmd,"%03lx",neu);
  506.                 break;
  507.               }
  508.              sprintf(&str,"Neue Portadresse:  $%s",&cmd);
  509.              DrawCNTextBorder(win,130,74,310,12,&str);
  510.             break;
  511.           }
  512.          break;
  513.       }
  514.     }
  515.    DeleteStdWindow(win);
  516.   }
  517.  return(neu);
  518. }
  519.  
  520.  
  521. /* TimeOut ändern */
  522. UWORD TimeOut(titel,alt,def)
  523.  UBYTE *titel;
  524.  UWORD  alt,def;
  525. {
  526.  UBYTE                         str[30];
  527.  UBYTE                        *zahl;
  528.  UWORD                         neu;
  529.  REGISTER UWORD                i,j;
  530.  REGISTER BOOL                 ende;
  531.  REGISTER ULONG                Class;
  532.  register struct Window       *win;
  533.  register struct Gadget       *gad;
  534.  register struct IntuiMessage *msg;
  535.  register struct RastPort     *rp;
  536.  register struct TextFont     *opal;
  537.  
  538.  neu=alt;
  539.  win=CreateStdWindow(titel,75,75,450,50,GADGETUP|CLOSEWINDOW,
  540.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  541.  if(win!=NULL)
  542.   {
  543.    rp=win->RPort;
  544.    opal=GetOpalFont();
  545.    SetFont(rp,opal);
  546.    CreateBoolGadget(win,10,15,115,12,"Okay",100);
  547.    CreateBoolGadget(win,130,15,115,12,"Abbruch",200);
  548.    sprintf(&str,"Original: %ld",def);
  549.    CreateBoolGadget(win,250,15,190,12,&str,300);
  550.    SelectStdFPen(rp);
  551.    WriteText(rp,15,43,"Anzahl der Zähler für Time-Out:");
  552.    sprintf(&str,"%ld",alt);
  553.    zahl=CreateIntegerGadget(win,340,35,100,10,&str,4,400);
  554.    ende=FALSE;
  555.    while(ende==FALSE)
  556.     {
  557.      WaitPort(win->UserPort);
  558.      msg=GetMsg(win->UserPort);
  559.      gad=msg->IAddress;
  560.      Class=msg->Class;
  561.      ReplyMsg(msg);
  562.      switch(Class)
  563.       {
  564.        case CLOSEWINDOW:
  565.          neu=alt;
  566.          ende=TRUE;
  567.         break;
  568.        case GADGETUP:
  569.          i=gad->GadgetID;
  570.          switch(i)
  571.           {
  572.            case 100:
  573.              neu=atol(zahl);
  574.              if(neu>255) neu=255;
  575.              ende=TRUE;
  576.             break;
  577.            case 200:
  578.              neu=alt;
  579.              ende=TRUE;
  580.             break;
  581.            case 300:
  582.              neu=def;
  583.              ende=TRUE;
  584.             break;
  585.           }
  586.         break;
  587.       }
  588.     }
  589.    DeleteStdWindow(win);
  590.   }
  591.  return(neu);
  592. }
  593.  
  594.